package br.com.adimoveis.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Insets;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

public class TableRenderer extends JPanel implements TableCellRenderer {
   
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private JLabel label;
	
	private Font plainFont = new Font("Tahoma",Font.PLAIN,11);
	
	private Font boldFont = new Font("Tahoma",Font.BOLD,11);
	
	public TableRenderer(){
		super(new BorderLayout());
		label = new JLabel();
		add(label, BorderLayout.CENTER);
	}
	
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int rowIndex, int vColIndex) {

    	if(rowIndex % 2 == 1){
    		setBackground(new Color(245,245,245));
    		revalidate();
    	}else{
    		setBackground(Color.WHITE);
    	}
    	
        if (isSelected) {
        	label.setFont(boldFont);
        	setBackground(new Color(255,230,151));
        }else{
        	label.setFont(plainFont);
        }

        if(value != null){
        	label.setText(value.toString());
        }else{
        	label.setText("");
        }
        
        return this;
    }
    
    @Override
    public Insets getInsets() {
    	return new Insets(2,2,2,2);
    }
}
